package com.example.nacosdemo.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    // 注入当前服务的端口号和服务名
    @Value("${server.port}")
    private String port;

    @Value("${spring.application.name}")
    private String serviceName;

    @GetMapping("/")
    public String hello() {
        return "Hello from " + serviceName + " running on port " + port + " (registered in Nacos)";
    }

    @GetMapping("/health")
    public String health() {
        return "Service " + serviceName + " is healthy";
    }
}